package com.layoutdinamico;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;

public class layoutdinamicoActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ScrollView scroll = new ScrollView(layoutdinamicoActivity.this);
		
		LinearLayout layout = new LinearLayout(layoutdinamicoActivity.this);
		layout.setOrientation(layout.VERTICAL);

		for (int i = 0; i < 50; i++) {
			Button button = new Button(layoutdinamicoActivity.this);
			button.setText("" + i);
			button.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Button button = (Button)v;
					Toast.makeText(layoutdinamicoActivity.this,
							"Ha pulsado el boton " + button.getText(), Toast.LENGTH_LONG).show();
					
				}
			});
			layout.addView(button);
		}
		scroll.addView(layout);
		setContentView(scroll);
	}
}